﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace zerototext
{
    class Program
    {
        static string outputfilename;
        static void Main(string[] args)
        {
            Console.Write("Output filename: ");
            outputfilename = Console.ReadLine();
            FileStream fstream = new FileStream(outputfilename, FileMode.Append);
            StringBuilder sbuilder = new StringBuilder("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
            uint i;
            i = 0;
            sbuilder.Append(sbuilder.ToString());
            sbuilder.Append(sbuilder.ToString()); sbuilder.Append(sbuilder.ToString()); sbuilder.Append(sbuilder.ToString()); sbuilder.Append(sbuilder.ToString()); sbuilder.Append(sbuilder.ToString());
            System.Threading.Thread speedcounterthread = new System.Threading.Thread(new System.Threading.ThreadStart(speedcounter));
            speedcounterthread.Start();

            while (true)
            {
                i = 0;
                Console.WriteLine("Current filesize: " + (new FileInfo(outputfilename).Length / 1048576).ToString() + "MByte");
                while (i < 900)
                {

                    i++;
                    fstream.Write(System.Text.Encoding.ASCII.GetBytes(sbuilder.ToString()), 0, sbuilder.Length);
                }
            }
        }

        public static void speedcounter()
        {
            long previoussize = 0; int curspeed = 0;
                List<long> longtermavg = new List<long>();
            while (true)
            {
                if (longtermavg.Count > 100) { longtermavg.RemoveAt(longtermavg.Count - 1); }

                    curspeed = Convert.ToInt32((new FileInfo(outputfilename).Length / 1048576) - previoussize);

                    if (previoussize > 1)
                    {
                        longtermavg.Add(curspeed);

                        Console.WriteLine("current speed: " + curspeed.ToString() + "MByte/s -- long term avg: " + longtermavg.Average() + "mb/s");
               
                    }
     previoussize = (new FileInfo(outputfilename).Length / 1048576);

                    System.Threading.Thread.Sleep(1000);


                
            }
        }
    }
}
